<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<script src="calendar_beans_v2.0_hide.js" type="text/javascript"charset="utf-8"></script>
<script src="jquery-1.7.2.js" type="text/javascript" charset="utf-8"></script>
<script>
	$(document).ready(function(){
		$("#movie").change(function(){
			if($(this).val()=="default")
				return false;
			$.ajax({
				url:"admin.do?command=getLocalAsMovieNo&movie_no="+$(this).val(),
				dataType:"json",
				success:function(js){
					var select = "<select name='local' id='local'><option value='default'>지역선택</option>";
					$.each(js.map.list,function(indexl,value){
						select+="	<option value="+value.LOC_NO+">"+value.LOC+"</option>";
					});
					select += "</select>";
					$("#local_span").html(select);
					$("#time_table_div").html(showTimeTable(js.map.tlist));
				}
			});
		}); // movie change
		$("#local_span").on("change","#local",function(){
			if($(this).val()=="default")
				return false;
			else if($("#movie").val()=="default"){
				alert("영화를 선택해주세요!");
				return false;
			}
			$.ajax({
				url:"admin.do?command=getTheaterAsLocalNoAndMovleNo&local_no="+$(this).val()+"&movie_no="+$("#movie").val(),
				dataType:"json",
				success:function(js){
					var select = "<select name='theater' id='theater'><option value='default'>영화관선택</option>";
					$.each(js.map.list,function(indexl,value){
						select+="	<option value="+value.THEATER_NO+">"+value.THEATER+"</option>";
					});
					select += "</select>";
					$("#theater_span").html(select);
					$("#time_table_div").html(showTimeTable(js.map.tlist));
				}
			});
		}); // local change
		$("#theater_span").on("change","#theater",function(){
			if($(this).val()=="default")
				return false;
			else if($("#movie").val()=="default"){
				alert("영화를 선택해주세요!");
				return false;
			}else if($("#local").val()=="default"){
				alert("지역을 선택해주세요!");
				return false;
			}
			$.ajax({
				url:"admin.do?command=getPlayRoomAndPossibleDateAsTheaterNoAndMovieNo&theater_no="+$(this).val()+"&movie_no="+$("#movie").val()+"&local_no="+$("#local ").val(),
				dataType:"json",
				success:function(js){
					var select = "<select name='play_room' id='play_room'><option value='default'>상영관선택</option>";
					$.each(js.map.play_room,function(indexl,value){
						select+="	<option value="+value.PLAY_ROOM_NO+">"+value.PLAY_ROOM_NO+"관</option>";
					});
					select += "</select>";
					$("#time_table_div").html(showTimeTable(js.map.tlist));
					$("#play_room_span").html(select);
					$("#possible_date_span").html(js.map.possible_date.STARTING_DAY+" ~ "+js.map.possible_date.ENDING_DAY);
				}
			});
		}); // theater change
		$("#play_room_span").on("change","#play_room",function(){
			if($(this).val()=="default")
				return false;
			else if($("#movie").val()=="default"){
				alert("영화를 선택해주세요!");
				return false;
			}else if($("#local").val()=="default"){
				alert("지역을 선택해주세요!");
				return false;
			}else if($("#theater").val()=="default"){
				alert("영화관을 선택해주세요!");
				return false;
			}
			$.ajax({
				url:"admin.do?command=getTimeTableAsAllNo&theater_no="+$("#theater").val()+"&movie_no="+$("#movie").val()+"&local_no="+$("#local ").val()+"&play_room_no="+$(this).val(),
				dataType:"json",
				success:function(js){
					$("#time_table_div").html(showTimeTable(js.tlist));
				}
			});
		}); // theater change
		$("#resetBtn").click(function(){
			location.href="admin.do?command=timetable_admin";
		}); // resetBtn click
		$("#registerBtn").click(function(){
			if($("#movie").val()=="default"){
				alert("영화를 선택해주세요!");
				return false;
			}else if($("#local").val()=="default"){
				alert("지역을 선택해주세요!");
				return false;
			}
			else 	if($("#theater").val()=="default"){
				alert("영화관을 선택해주세요!");
				return false;
			}
			else 	if($("#play_room").val()=="default"){
				alert("상영관 선택해주세요!");
				return false;
			}
			else 	if($("#timetablecal1").val()==""){
				alert("날짜를 선택해주세요!");
				return false;
			}
			alert($("#timeTableInfo").serialize());
			location.href="admin.do?command=timeTableRegister&"+$(" #timeTableInfo").serialize();
		}); //registerBtn click
		$("#regDayBtn").click(function(){
			if($("#movie").val()=="default"){
				alert("영화를 선택해주세요!");
				return false;
			}else if($("#local").val()=="default"){
				alert("지역을 선택해주세요!");
				return false;
			}
			else 	if($("#theater").val()=="default"){
				alert("영화관을 선택해주세요!");
				return false;
			}
			else 	if($("#play_room").val()=="default"){
				alert("상영관 선택해주세요!");
				return false;
			}
			else 	if($("#timetablecal1").val()==""){
				alert("날짜를 선택해주세요!");
				return false;
			}
			alert($("#timeTableInfo").serialize());
			location.href="admin.do?command=timeTableOneDayRegister&"+$(" #timeTableInfo").serialize();
		}); //regDayBtn click
		$("#time_table_div").on('click','#time_table_delete_btn',function(){
			var arr = [];
			var flag=true;
			var delcheckbox = document.getElementsByName("delcheckbox");
			for(i=0;i<delcheckbox.length;i++){
				if(delcheckbox[i].checked){
					arr.push(delcheckbox[i].value);
					flag=false;
				}
			}
			if(flag){
				alert("삭제하실 시간표를 선택하세요."); 
				return false;
			}
			if(confirm(arr.toString()+'을 삭제하시겠습니까?')){
				$.ajax({
					url:"admin.do?command=timetableDelete&list="+arr.toString(),
					dataType:"json",
					success:function(js){
						alert("삭제성공 :"+js.map.success+", 삭제실패 : "+js.map.fail);
						location.href="admin.do?command=timetable_admin";
					}
				});
			}
		}); // 선택삭제 button click
		$("#AllDeleteBtn").click(function(){
			if(confirm("모든 상영표를 삭제하시겠습니까?")){
				$.ajax({
					url:"admin.do?command=timetableAllDelete",
					dataType:"json",
					success:function(js){
						alert("삭제성공 :"+js.map.success+", 삭제실패 : "+js.map.fail);
						location.href="admin.do?command=timetable_admin";
					}
				});
			}
		});
		$("#time_table_div").on('click','.allcheckclass',function() {
			var flag = $(this).attr("checked");
			$(".delcheckboxclass").each(function() {
				var subChecked = $(this).attr("checked");
				if (subChecked != flag)
					$(this).click();
			});
		});// 모두선택 checkbox
	}); //ready
	function showTimeTable(data){
		var table="상영표 현황 [TOTAL :  "+data.length+"]<br><table border='1' width='95%'><tr align='center' bgcolor='#f5f5f5'>	<td>순서</td><td>영화</td><td>지역</td><td>영화관</td><td>상영관</td><td>시작시간</td><td>종료시간</td><td><input type='checkbox' class='allcheckclass' name='Allcheck'></td><td>no</td></tr>";
		for(i=0;i<data.length;i++){
			table+="<tr align='center'><td>"+data[i].RN+"</td><td>"+data[i].MOVIE_TITLE+"</td><td>"+data[i].LOC+"</td><td>"+data[i].THEATER+"</td><td>"+data[i].PLAY_ROOM_NO+"</td><td>"+data[i].STARTING_TIME+"</td>"+
			"<td>"+data[i].ENDING_TIME+"</td><td><input type='checkbox' class='delcheckboxclass' name='delcheckbox' value='"+data[i].TIME_TABLE_NO+"'></td><td>"+data[i].TIME_TABLE_NO+"</td></tr>";
		}
		table+="</table><input type='button' value='선택삭제' id='time_table_delete_btn'><br>";
		return table;
	}
</script>
<span class="title">상영표관리</span><hr color="#f5f5f5">
<c:choose>
<c:when test="${sessionScope.vo.memberlevelinfoVO.member_level_no !=1}">
<script>
	alert("잘못된 접근입니다!");           
	location.href="mycinema.do?command=home_main";
</script>
</c:when>
<c:otherwise>
	<form id="timeTableInfo">
		<table border="1" width="100%">
			<tr align="center" bgcolor="#f5f5f5" >
				<td>영화</td>
				<td>지역</td>
				<td>영화관</td>
				<td>상영관</td>
				<td width="150">등록가능기간</td>
				<td>상영일</td>
				<td width="15%">상영시작시간</td>
			</tr>
			<tr>
				<td><span id="movie_span">
				<select id="movie" name="movie">	<option value="default">영화선택</option>
							<c:forEach	items="${requestScope.map.movie }" var="m">
								<option value="${m.MOVIE_NO }">${m.MOVIE_TITLE}</option>
							</c:forEach>
				</select>
				</span></td>
				<td><span id="local_span">
				<select name="local" id="local"><option value="default">지역선택</option>
							<c:forEach items="${requestScope.map.local }" var="l">
								<option value="${l.LOC_NO }">${l.LOC}</option>
							</c:forEach>
				</select>
				</span></td>
				<td><span id="theater_span">
				<select name="theater" id="theater"><option value="default">영화관선택</option>
							<c:forEach items="${requestScope.map.theater }" var="t">
									<option value="${t.THEATER_NO }">${t.THEATER}</option>
							</c:forEach>
				</select>
				</span></td>
				<td><span id="play_room_span">
				<select name="play_room" id="play_room"><option value="default">상영관선택</option>
				</select>
				</span></td>
				<td>
					<span id="possible_date_span"><font color="gray">상영관을선택하세요</font> 
					</span>
				</td>
				<td><input type="text" id="timetablecal1" name="day" size="10"
					readonly="readonly" placeholder="select.." value=""></td>
				<td><select name="hour">
						<c:forEach begin="1" end="21" var="i">
							<option value="${i }">${i }</option>
						</c:forEach>
				</select>시<select name="minute">
						<c:forEach begin="00" end="50" var="i" step="10">
							<c:if test="${i==0 }"><option value="00">00</option></c:if>
							<c:if test="${i!=0 }"><option value="${i }">${i }</option></c:if>
						</c:forEach>
				</select>분</td>
			</tr>
		</table>
	</form>
<input type="button" value="reset" id="resetBtn"  style="width:70px"><input type="button" value="등록하기" id="registerBtn" ><input type="button" value="하루등록" id="regDayBtn"  >
	<br><br>
<div id="time_table_div">
		상영표 현황 [TOTAL :  ${map.total}]<br>  
	<table border="1" width="95%" id="time_table_table">
		<tr align="center" bgcolor="#f5f5f5">
			<td>순번</td>
			<td>영화</td>
			<td>지역</td>
			<td>영화관</td>
			<td>상영관</td>
			<td>시작시간</td>
			<td>종료시간</td>
			<td><input type="checkbox" class="allcheckclass" name="Allcheck"></td>
			<td>no</td>
		</tr>
		<c:forEach items="${requestScope.map.time_table.list }" var="tt">
		<tr align="center">
			<td>${tt.RN}</td>
			<td>${tt.MOVIE_TITLE }</td>
			<td>${tt.LOC }</td>
			<td>${tt.THEATER }</td>
			<td>${tt.PLAY_ROOM_NO}</td>
			<td>${tt.STARTING_TIME }</td>
			<td>${tt.ENDING_TIME}</td>
			<td><input type="checkbox" class='delcheckboxclass' name="delcheckbox" value="${tt.TIME_TABLE_NO }"></td>
			<td>${tt.TIME_TABLE_NO }</td>
		</tr>
		</c:forEach>
	</table>
					
	<input type="button" value="모두삭제" id="AllDeleteBtn"><input type="button" value="선택삭제" id="time_table_delete_btn"><br>
	<!-- 페이징 처리 -->	
	 <c:if test="${requestScope.map.time_table.pagingBean.previousPageGroup}">
	 <a href="admin.do?command=timetable_admin&pageNo=${requestScope.map.time_table.pagingBean.startPageOfPageGroup-1}">
	 	<img src="img.board/left_arrow_btn.gif"></a></c:if> &nbsp;&nbsp;
	<c:forEach var="i" begin="${requestScope.map.time_table.pagingBean.startPageOfPageGroup}" end="${requestScope.map.time_table.pagingBean.endPageOfPageGroup}">
	 	<c:choose><c:when test="${requestScope.map.time_table.pagingBean.nowPage!=i}">
	 			<a href="admin.do?command=timetable_admin&pageNo=${i}">${i}</a>
	 		</c:when><c:otherwise><u>${i}</u></c:otherwise></c:choose></c:forEach>&nbsp;&nbsp;
	 <c:if test="${requestScope.map.time_table.pagingBean.nextPageGroup}">
	  	<a href="admin.do?command=timetable_admin&pageNo=${requestScope.map.time_table.pagingBean.endPageOfPageGroup+1}">
	 	<img src="img.board/right_arrow_btn.gif"></a> </c:if>	 	
	 	</div>
<script type="text/javascript">
	CalAddCss(); // !!제일 상단에 필수!!
	initCal({	id : "timetablecal1",type : "day",today : "y",icon : "y"});
</script>
	 	</c:otherwise>
</c:choose>